// Author: Ivan Chau
package uk.ac.cam.kcic2.photonMap;

import java.util.Comparator;

import uk.ac.cam.kcic2.math.Vector3D;

public class PhotonComparator implements Comparator<Photon> {

	public final Vector3D queryPoint;
	
	public PhotonComparator(Vector3D point){
		super();
		queryPoint = point;
	}
	
	@Override
	public int compare(Photon p1, Photon p2) {
		Vector3D p1FromQuery = p1.position.sub(queryPoint);
		Vector3D p2FromQuery = p2.position.sub(queryPoint);
		
		double dist1 = p1FromQuery.norm();
		double dist2 = p2FromQuery.norm();
		
		// negate to make a max heap
		return -Double.compare(dist1, dist2);
	}

}
